package com.example.octopus.service;
import com.example.octopus.entity.WeixinAccessToken;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class WeixinAccessTokenServiceImpl implements WeixinAccessTokenService{

    private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token";

    public WeixinAccessToken getAccessToken(String appid, String secret) {
        RestTemplate restTemplate = new RestTemplate();
        String url = TOKEN_URL + "?grant_type=client_credential&appid=" + appid + "&secret=" + secret;
        ResponseEntity<WeixinAccessToken> response = restTemplate.getForEntity(url, WeixinAccessToken.class);
        return response.getBody();
    }
}